import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path*',
      component: () => import('@/views/redirect/index')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: Layout,
    hidden: true,
    children: [{
      path: "",
      component: () => import('@/views/404')
    }]
  },
  {
    path: '/',
    hidden: true,
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '机构管理列表',
      component: () => import('@/views/dashboard/index')
    }]
  },
  /*{
    path: '/example',
    component: Layout,
    redirect: '/example/dashboard',
    name: '机构管理',
    meta: {title: '机构管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'dashboard',
        name: '机构列表',
        component: () => import('@/views/dashboard/index'),
        meta: {title: '机构列表', icon: ''}
      },
      {
        path: 'register',
        name: '机构注册',
        component: () => import('@/views/register/index'),
        meta: {title: '机构注册', icon: ''}
      },
      {
        path: 'organDetail',
        component: () => import('@/views/organDetail/index'),
        name: '机构详情',
        meta: {title: '机构详情'}
      },
    ]
  },*/
  /*     {
         path: '/nested',
         component: Layout,
         redirect: '/nested/menu',
         name: '机构详情 ',
         meta: {
           title: '机构详情',
           icon: 'nested'
         },
         children: [*/
  /*         {
             path: '/nested/menu1',
             component: Layout,
             redirect: '/nested/menu1/menu1-1',
             name: '机构课程 ',
           },*/


  /*{
    path: 'class',
    component: () => import('@/views/class/index'), // Parent router-view
    name: '机构课程',
    meta: {title: '机构课程'},
    children: [
      {
        path: 'classAdd',
        component: () => import('@/views/class/add'),
        name: '机构课程列表',
        meta: {title: '机构课程列表'}
      },
      {
        path: 'classList',
        component: () => import('@/views/class/list'),
        name: '机构课程添加',
        meta: {title: '机构课程添加'}
      }
    ]
  },*/



  /* {
     path: '/nested/menu2',
     component: Layout,
     redirect: '/nested/menu2/menu1-3',
     name: '机构校区 ',
   },*/
  /* {
     path: 'schoolArea',
     component: () => import('@/views/schoolArea/index'), // Parent router-view
     name: '机构校区',
     meta: {title: '机构校区'},
     children: [
       {
         path: 'schoolList',
         component: () => import('@/views/schoolArea/list'),
         name: '机构校区列表',
         meta: {title: '机构校区列表'}
       },
       {
         path: 'schoolDetail',
         component: () => import('@/views/schoolArea/detail),
         name: '机构校区添加',
         meta: {title: '机构校区添加'}
       }
     ]
   },
  /!* {
     path: '/nested/menu3',
     component: Layout,
     redirect: '/nested/menu3/menu1-5',
     name: '机构师资 ',
   },*!/
   {
     path: 'teacher',
     component: () => import('@/views/teacher/index'), // Parent router-view
     name: '机构师资',
     meta: {title: '机构师资'},
     children: [
       {
         path: 'teacherList',
         component: () => import('@/views/teacher/list'),
         name: '机构师资列表',
         meta: {title: '机构师资列表'}
       },
       {
         path: 'teacherDetail',
         component: () => import('@/views/teacher/detail'),
         name: '机构师资添加',
         meta: {title: '机构师资添加'}
       }
     ]
   },
   /!*{
     path: '/nested/menu4',
     component: Layout,
     redirect: '/nested/menu4/menu1-7',
     name: '机构相册 ',
   },*!/
   {
     path: 'photo',
     component: () => import('@/views/photo/index'), // Parent router-view
     name: '机构相册',
     meta: {title: '机构相册'},
     children: [
       {
         path: 'photoList',
         component: () => import('@/views/photo/list'),
         name: '机构相册列表',
         meta: {title: '机构相册列表'}
       },
       {
         path: 'photoDetail',
         component: () => import('@/views/photo/detail'),
         name: '机构相册添加',
         meta: {title: '机构相册添加'}
       }
     ]
   },*/
  /*       ]
       },*/

  /* {
     path: 'classify',
     component: () => import('@/views/classify/index'),
     name: 'classify',
     meta: {title: '课程分类', icon: 'el-icon-menu'},
     children: [
       {
         path: 'classifyList',
         component: () => import('@/views/classify/list'),
         name: '课程分类列表',
         meta: {title: '课程分类列表'}
       },
       {
         path: 'classifyAdd',
         component: () => import('@/views/classify/add'),
         name: '添加课程分类',
         meta: {title: '添加课程分类'}
       }
     ]
   },*/
  /* {
     path: 'city',
     component: () => import('@/views/city/index'),
     name: 'city',
     meta: {title: '城市数据', icon: 'el-icon-location'},
     children: [
       {
         path: 'cityList',
         component: () => import('@/views/city/list'),
         name: '城市数据列表',
         meta: {title: '城市数据列表'}
       },
       {
         path: 'cityAdd',
         component: () => import('@/views/city/add'),
         name: '添加城市数据',
         meta: {title: '添加城市数据'}
       }
     ]
   },*/

  /*  {
      path: '/ums',
      component: Layout,
      redirect: '/ums/admin',
      name: 'ums',
      meta: {title: '权限', icon: 'ums'},
      children: [
        {
          path: 'admin',
          name: 'admin',
          component: () => import('@/views/ums/admin/index'),
          meta: {title: '用户列表', icon: ''} /!* ums-admin*!/
        },
        {
          path: 'role',
          name: 'role',
          component: () => import('@/views/ums/role/index'),
          meta: {title: '角色列表', icon: ''}   /!*ums-role*!/
        },
        {
          path: 'menu',
          name: 'menu',
          component: () => import('@/views/ums/menu/index'),
          meta: {title: '菜单列表', icon: ''} /!* ums-menu*!/
        },
        {
          path: 'allocMenu',
          name: 'allocMenu',
          component: () => import('@/views/ums/role/allocMenu'),
          meta: {title: '分配菜单'},
          hidden: true
        },
        {
          path: 'allocResource',
          name: 'allocResource',
          component: () => import('@/views/ums/role/allocResource'),
          meta: {title: '分配资源'},
          hidden: true
        },
        {
          path: 'addMenu',
          name: 'addMenu',
          component: () => import('@/views/ums/add'),
          meta: {title: '添加菜单'},
          hidden: true
        },
        {
          path: 'updateMenu',
          name: 'updateMenu',
          component: () => import('@/views/ums/update'),
          meta: {title: '修改菜单'},
          hidden: true
        }
      ]
    },*/
  // 404 page must be placed at the end !!!
  // {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
